// merchants/tixianRequest/index.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    CurrentPage: 1,
    loadingMoreHidden: 1,
    requestList: []
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    this.getRequestList();
  },
  // 提现申请记录
  getRequestList: function() {
    let that = this;
    wx.request({
      url: app.globalData.host + '/api/Shareholder/GetRequestList',
      data: {
        createUid: app.globalData.userInfo.Uid,
        uid: 0,
        page: that.data.CurrentPage
      },
      success: function(res) {
        if (res.data.Code == 0) {
          let requestList = [];
          if (res.data.Data) {
            requestList = res.data.Data.List;
            if (that.data.CurrentPage != 1) {
              var preGoods = that.data.requestList;
              requestList = preGoods.concat(requestList);
            }
            that.setData({
              requestList: requestList,
              loadingMoreHidden: res.data.Data.PageModel.TotalPages
            })
          }
        } else {
          wx.showModal({
            title: '提示',
            content: res.data.Message,
            showCancel: false
          })
        }
      }
    })
  },

  // 加载更多
  loadMore: function (e) {
    var that = this;
    if (that.data.loadingMoreHidden > 1 && that.data.CurrentPage < that.data.loadingMoreHidden) {
      var currPage = that.data.CurrentPage;
      that.setData({
        CurrentPage: currPage + 1
      })
      that.getRequestList();
    } else {
      return
    }
  },

  // 同意申请
  changeStatus: function(e) {
    let that = this;
    let id = e.currentTarget.dataset.id;
    wx.showModal({
      title: '提示',
      content: '确认同意申请？',
      success(res) {
        if (res.confirm) {
          wx.request({
            url: app.globalData.host + '/api/Shareholder/SetRequestStatus',
            data: {
              id: id,
              createUid: app.globalData.userInfo.Uid,
              status: 1 //0申请中，1已发放
            },
            success: function(res) {
              if (res.data.Code == 0) {
                wx.showToast({
                  title: '发放成功',
                  duration: 1000
                })
                that.getRequestList();
              } else {
                wx.showModal({
                  title: '提示',
                  content: res.data.Message,
                  showCancel: false
                })
              }
            }
          })
        }
      }
    })

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  }


})